<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    let map = {
      ']': '[',
      '}': '{',
      ')': '(',
    }
    function test(str) {
      let stash = []
      let index = 0
      while (index < str.length) {
        let val = map[str[index]]
        if (!val) {
          stash.push(str[index])
        } else {
          if (val !== stash.pop()) return false
        }
        index++
      }
      return stash.length === 0
    }
    let str = '({[]})'
    let result = test(str)
    console.log(result);
    let str1 = '({[[})'
    let result2 = test(str1)
    console.log(result2);
    let str2 = '()'
    let result3 = test(str2)
    console.log(result3);
  </script>
</body>

</html>